/*
 * Payment.java
 *
 * Created on Mar 14, 2011, 2:59:14 PM
 */

package pos.ui.screen;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import pos.config.LoadConfig;
import pos.control.CustomerDetailsControl;
import pos.control.PaymentControl;
import pos.entity.Order;
import pos.entity.PaymentDetails;
import pos.exception.POSException;
import pos.interfaces.Messages;
import pos.util.DisplayMessage;
import pos.util.IDGenerator;



/**
 * This class does the process payment operation and gives a feedback to the user
 * that the transaction is completed or failed.
 * @author vmm
 */
public class Payment extends javax.swing.JFrame implements KeyListener {

    private Order order = null;
    private PaymentDetails  paymentDetails= null;
    /**
     * Create the payment object.
     */
    public Payment() {
        setTitle("Payment Screen");
        initComponents();
        order = new Order();
        paymentDetails = new PaymentDetails();
        PaymentCardNumTF.addKeyListener(this);
        PaymentCardNumTF2.addKeyListener(this);
        PaymentCardNumTF3.addKeyListener(this);
        PaymentCardNumTF4.addKeyListener(this);
        SecurityNumTF.addKeyListener(this);
        PayByCredit.setSelected(true);
        cardLable1.setIcon( new ImageIcon (pos.Pos.conf.getExtDirs().get("images") + "\\credit1.gif"));
        cardLable2.setIcon( new ImageIcon (pos.Pos.conf.getExtDirs().get("images") + "\\credit2.jpg"));
        cardLable3.setIcon( new ImageIcon (pos.Pos.conf.getExtDirs().get("images") + "\\debitcard.gif"));
    }
    /**
     * Set the order
     * @param order
     */
    public void setOrder(Order order){
        this.order = order;
    }
    /**
     * Get the order
     * @return
     */
    public Order getOrder(){
        return this.order;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        CardNumTF = new javax.swing.JTextField();
        PhoneNumTF = new javax.swing.JTextField();
        paymentPanel = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        PayByCredit = new javax.swing.JRadioButton();
        PayByDebit = new javax.swing.JRadioButton();
        PayByCash = new javax.swing.JRadioButton();
        cardNoLable = new javax.swing.JLabel();
        ExpirationLable = new javax.swing.JLabel();
        month = new javax.swing.JComboBox();
        year = new javax.swing.JComboBox();
        monthLable = new javax.swing.JLabel();
        yearLable = new javax.swing.JLabel();
        SecurityNoLable = new javax.swing.JLabel();
        MessageLable = new javax.swing.JLabel();
        NameOrAmountLable = new javax.swing.JLabel();
        NameTF = new javax.swing.JTextField();
        slashLable1 = new javax.swing.JLabel();
        slashLable2 = new javax.swing.JLabel();
        slashLable3 = new javax.swing.JLabel();
        SecurityNumTF = new javax.swing.JTextField();
        PaymentCardNumTF = new javax.swing.JTextField();
        PaymentCardNumTF2 = new javax.swing.JTextField();
        PaymentCardNumTF3 = new javax.swing.JTextField();
        PaymentCardNumTF4 = new javax.swing.JTextField();
        submit = new javax.swing.JButton();
        clear = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        cardLable3 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        cardLable1 = new javax.swing.JLabel();
        cardLable2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText("Member Login (Member Only)");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 10, 250, 30);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel2.setText("Store Card No:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(20, 60, 150, 40);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel3.setText("Phone No:");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(20, 130, 120, 22);

        CardNumTF.setFont(new java.awt.Font("Tahoma", 0, 18));
        jPanel1.add(CardNumTF);
        CardNumTF.setBounds(140, 60, 250, 40);

        PhoneNumTF.setFont(new java.awt.Font("Tahoma", 0, 18));
        jPanel1.add(PhoneNumTF);
        PhoneNumTF.setBounds(140, 120, 250, 40);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(70, 30, 520, 170);

        paymentPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        paymentPanel.setLayout(null);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel4.setText("Payment Information");
        paymentPanel.add(jLabel4);
        jLabel4.setBounds(20, 10, 180, 30);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel5.setText("Cards:");
        paymentPanel.add(jLabel5);
        jLabel5.setBounds(30, 50, 90, 30);

        PayByCredit.setFont(new java.awt.Font("Tahoma", 0, 18));
        PayByCredit.setText(" Credit ");
        PayByCredit.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        PayByCredit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PayByCreditActionPerformed(evt);
            }
        });
        paymentPanel.add(PayByCredit);
        PayByCredit.setBounds(140, 50, 120, 31);

        PayByDebit.setFont(new java.awt.Font("Tahoma", 0, 18));
        PayByDebit.setText("Debit ");
        PayByDebit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PayByDebitActionPerformed(evt);
            }
        });
        paymentPanel.add(PayByDebit);
        PayByDebit.setBounds(270, 50, 110, 30);

        PayByCash.setFont(new java.awt.Font("Tahoma", 0, 18));
        PayByCash.setText("Cash ");
        PayByCash.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PayByCashActionPerformed(evt);
            }
        });
        paymentPanel.add(PayByCash);
        PayByCash.setBounds(400, 50, 110, 30);

        cardNoLable.setFont(new java.awt.Font("Tahoma", 0, 18));
        cardNoLable.setText("*Card No:");
        paymentPanel.add(cardNoLable);
        cardNoLable.setBounds(20, 100, 90, 30);

        ExpirationLable.setFont(new java.awt.Font("Tahoma", 0, 18));
        ExpirationLable.setText("*Expiration:");
        paymentPanel.add(ExpirationLable);
        ExpirationLable.setBounds(20, 150, 100, 40);

        month.setFont(new java.awt.Font("Tahoma", 0, 18));
        month.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));
        month.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monthActionPerformed(evt);
            }
        });
        paymentPanel.add(month);
        month.setBounds(140, 150, 70, 40);

        year.setFont(new java.awt.Font("Tahoma", 0, 18));
        year.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
        paymentPanel.add(year);
        year.setBounds(270, 150, 90, 40);

        monthLable.setFont(new java.awt.Font("Tahoma", 0, 14));
        monthLable.setText("/Month");
        paymentPanel.add(monthLable);
        monthLable.setBounds(220, 160, 50, 30);

        yearLable.setFont(new java.awt.Font("Tahoma", 0, 14));
        yearLable.setText("/Year");
        paymentPanel.add(yearLable);
        yearLable.setBounds(370, 160, 42, 30);

        SecurityNoLable.setFont(new java.awt.Font("Tahoma", 0, 18));
        SecurityNoLable.setText("*Security No:");
        paymentPanel.add(SecurityNoLable);
        SecurityNoLable.setBounds(20, 210, 110, 40);

        MessageLable.setFont(new java.awt.Font("Tahoma", 0, 14));
        MessageLable.setText("(Three digits on the back of your card)");
        paymentPanel.add(MessageLable);
        MessageLable.setBounds(210, 220, 250, 30);

        NameOrAmountLable.setFont(new java.awt.Font("Tahoma", 0, 18));
        NameOrAmountLable.setText("Name:");
        paymentPanel.add(NameOrAmountLable);
        NameOrAmountLable.setBounds(30, 260, 90, 40);

        NameTF.setFont(new java.awt.Font("Tahoma", 0, 18));
        NameTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NameTFActionPerformed(evt);
            }
        });
        paymentPanel.add(NameTF);
        NameTF.setBounds(140, 261, 240, 40);

        slashLable1.setText("-");
        paymentPanel.add(slashLable1);
        slashLable1.setBounds(210, 120, 10, 10);

        slashLable2.setText("-");
        paymentPanel.add(slashLable2);
        slashLable2.setBounds(300, 120, 10, 10);

        slashLable3.setText("-");
        paymentPanel.add(slashLable3);
        slashLable3.setBounds(390, 120, 10, 10);

        SecurityNumTF.setFont(new java.awt.Font("Tahoma", 0, 18));
        paymentPanel.add(SecurityNumTF);
        SecurityNumTF.setBounds(140, 211, 60, 40);

        PaymentCardNumTF.setFont(new java.awt.Font("Tahoma", 0, 18));
        paymentPanel.add(PaymentCardNumTF);
        PaymentCardNumTF.setBounds(140, 101, 60, 40);

        PaymentCardNumTF2.setFont(new java.awt.Font("Tahoma", 0, 18));
        paymentPanel.add(PaymentCardNumTF2);
        PaymentCardNumTF2.setBounds(230, 100, 60, 40);

        PaymentCardNumTF3.setFont(new java.awt.Font("Tahoma", 0, 18));
        paymentPanel.add(PaymentCardNumTF3);
        PaymentCardNumTF3.setBounds(320, 100, 60, 40);

        PaymentCardNumTF4.setFont(new java.awt.Font("Tahoma", 0, 18));
        paymentPanel.add(PaymentCardNumTF4);
        PaymentCardNumTF4.setBounds(410, 100, 60, 40);

        getContentPane().add(paymentPanel);
        paymentPanel.setBounds(70, 220, 520, 320);

        submit.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        submit.setText("Submit");
        submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitActionPerformed(evt);
            }
        });
        getContentPane().add(submit);
        submit.setBounds(70, 550, 160, 70);

        clear.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        clear.setText("Clear");
        clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearActionPerformed(evt);
            }
        });
        getContentPane().add(clear);
        clear.setBounds(260, 550, 150, 70);

        cancel.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        cancel.setText("Close");
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        getContentPane().add(cancel);
        cancel.setBounds(440, 550, 150, 70);

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setLayout(null);
        jPanel3.add(cardLable3);
        cardLable3.setBounds(40, 440, 100, 90);

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel13.setText("Card Types");
        jPanel3.add(jLabel13);
        jLabel13.setBounds(40, 20, 90, 40);

        jLabel14.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel14.setText("Credit Card");
        jPanel3.add(jLabel14);
        jLabel14.setBounds(50, 180, 90, 16);

        jLabel15.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel15.setText("Credit Card");
        jPanel3.add(jLabel15);
        jLabel15.setBounds(50, 360, 80, 16);

        jLabel16.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel16.setText("Debit Card");
        jPanel3.add(jLabel16);
        jLabel16.setBounds(50, 530, 70, 15);
        jPanel3.add(cardLable1);
        cardLable1.setBounds(32, 100, 110, 60);
        jPanel3.add(cardLable2);
        cardLable2.setBounds(30, 290, 110, 60);

        getContentPane().add(jPanel3);
        jPanel3.setBounds(670, 30, 170, 590);

        setBounds(0, 0, 940, 705);
    }// </editor-fold>//GEN-END:initComponents

    private void PayByCreditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PayByCreditActionPerformed
        PayByCredit.setSelected(true);
        PayByDebit.setSelected(false);
        PayByCash.setSelected(false);
        this.enableFields();
    }//GEN-LAST:event_PayByCreditActionPerformed

    private void PayByDebitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PayByDebitActionPerformed
        PayByDebit.setSelected(true);
        PayByCredit.setSelected(false);
        PayByCash.setSelected(false);
        this.enableFields();
        MessageLable.setVisible(false);
        SecurityNoLable.setVisible(false);
        SecurityNumTF.setVisible(false);
    }//GEN-LAST:event_PayByDebitActionPerformed

    private void monthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_monthActionPerformed

    private void NameTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NameTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NameTFActionPerformed

    private void submitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitActionPerformed
        String storeCardNum = CardNumTF.getText().trim(); ;
        String phoneNum = PhoneNumTF.getText().trim();
        String paymentCardNum = PaymentCardNumTF.getText().trim()+PaymentCardNumTF2.getText().trim()
                +PaymentCardNumTF3.getText().trim()+PaymentCardNumTF4.getText().trim();
        String securityNum = SecurityNumTF.getText().trim();
        String name = NameTF.getText().trim();
        String expireMonth = month.getSelectedItem().toString();
        String expireYear = year.getSelectedItem().toString();
        String cardType;
        if(PayByCredit.isSelected()== true){
            cardType = "credit";
        } else if(PayByDebit.isSelected()== true){
            cardType = "debit";
        } else if(PayByCash.isSelected() == true){
            cardType = "cash";
        } else {
            cardType = null;
        }


        paymentDetails.setCardNumber(storeCardNum);
        paymentDetails.setCardType(cardType);
        paymentDetails.setExpiryMonth(expireMonth);
        paymentDetails.setExpiryYear(expireYear);
        paymentDetails.setPaymentCardBrand(null);
        paymentDetails.setPaymentCardNumber(paymentCardNum);
        paymentDetails.setPhoneNumber(phoneNum);
        paymentDetails.setSecurityNumber(securityNum);
        paymentDetails.setName(name);

        PaymentControl newPayControl = new PaymentControl();
        try {
          int status = newPayControl.handlePaymentDetails(paymentDetails, order);
          if(status == 2){
                 JOptionPane.showMessageDialog(this, Messages.invalidMember, Messages.infoDialogTitle, JOptionPane.PLAIN_MESSAGE);
                 this.dispose();
          }
          else if(status == 3 || status == 1){
                  JOptionPane.showMessageDialog(this, Messages.PaymentSuccess + " Your Order Id is " + order.getOrderId(), Messages.infoDialogTitle, JOptionPane.PLAIN_MESSAGE);
                  this.dispose();
          }
          else if(status == -1){
                 JOptionPane.showMessageDialog(this, Messages.invalidPayment, Messages.infoDialogTitle, JOptionPane.ERROR_MESSAGE);
          }
        } catch (POSException ex) {
            DisplayMessage dm = new DisplayMessage();
            dm.displayMessage(this, ex.getMessage(),"ERROR", JOptionPane.WARNING_MESSAGE);
        } catch (SQLException ex) {
            Logger.getLogger(Payment.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_submitActionPerformed

    private void PayByCashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PayByCashActionPerformed
        PayByCash.setSelected(true);
        PayByDebit.setSelected(false);
        PayByCredit.setSelected(false);
        this.disableFields();
    }//GEN-LAST:event_PayByCashActionPerformed

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearActionPerformed
        this.clearScreen();
    }//GEN-LAST:event_clearActionPerformed

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelActionPerformed
    /**
     * This method is used for clean the screen.
     */
    private void clearScreen(){
        CardNumTF.setText("");
        NameTF.setText("");
        PhoneNumTF.setText("");
        PaymentCardNumTF.setText("");
        PaymentCardNumTF2.setText("");
        PaymentCardNumTF3.setText("");
        PaymentCardNumTF4.setText("");
        SecurityNumTF.setText("");
        PayByCredit.setSelected(false);
        PayByDebit.setSelected(false);
        PayByCash.setSelected(false);
        month.setSelectedIndex(0);
        year.setSelectedIndex(0);
    }
    /**
     * This method is used for disable some fields in the screen.
     */
    private void disableFields(){
            ExpirationLable.setVisible(false);
            MessageLable.setVisible(false);
            monthLable.setVisible(false);
            NameOrAmountLable.setVisible(false);
            NameTF.setVisible(false);
            PaymentCardNumTF.setVisible(false);
            PaymentCardNumTF2.setVisible(false);
            PaymentCardNumTF3.setVisible(false);
            PaymentCardNumTF4.setVisible(false);
            SecurityNoLable.setVisible(false);
            SecurityNumTF.setVisible(false);
            cardNoLable.setVisible(false);
            slashLable1.setVisible(false);
            slashLable2.setVisible(false);
            slashLable3.setVisible(false);
            year.setVisible(false);
            month.setVisible(false);
            yearLable.setVisible(false);
            monthLable.setVisible(false);
    }
    /**
     * This method is used for enable fields of the screen.
     */
    private void enableFields(){
            ExpirationLable.setVisible(true);
            MessageLable.setVisible(true);
            monthLable.setVisible(true);
            NameOrAmountLable.setVisible(true);
            NameTF.setVisible(true);
            PaymentCardNumTF.setVisible(true);
            PaymentCardNumTF2.setVisible(true);
            PaymentCardNumTF3.setVisible(true);
            PaymentCardNumTF4.setVisible(true);
            SecurityNoLable.setVisible(true);
            SecurityNumTF.setVisible(true);
            cardNoLable.setVisible(true);
            slashLable1.setVisible(true);
            slashLable2.setVisible(true);
            slashLable3.setVisible(true);
            year.setVisible(true);
            month.setVisible(true);
            yearLable.setVisible(true);
            monthLable.setVisible(true);
    }
    /**
    * @param args the command line arguments
    */
    
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Payment().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CardNumTF;
    private javax.swing.JLabel ExpirationLable;
    private javax.swing.JLabel MessageLable;
    private javax.swing.JLabel NameOrAmountLable;
    private javax.swing.JTextField NameTF;
    private javax.swing.JRadioButton PayByCash;
    private javax.swing.JRadioButton PayByCredit;
    private javax.swing.JRadioButton PayByDebit;
    private javax.swing.JTextField PaymentCardNumTF;
    private javax.swing.JTextField PaymentCardNumTF2;
    private javax.swing.JTextField PaymentCardNumTF3;
    private javax.swing.JTextField PaymentCardNumTF4;
    private javax.swing.JTextField PhoneNumTF;
    private javax.swing.JLabel SecurityNoLable;
    private javax.swing.JTextField SecurityNumTF;
    private javax.swing.JButton cancel;
    private javax.swing.JLabel cardLable1;
    private javax.swing.JLabel cardLable2;
    private javax.swing.JLabel cardLable3;
    private javax.swing.JLabel cardNoLable;
    private javax.swing.JButton clear;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JComboBox month;
    private javax.swing.JLabel monthLable;
    private javax.swing.JPanel paymentPanel;
    private javax.swing.JLabel slashLable1;
    private javax.swing.JLabel slashLable2;
    private javax.swing.JLabel slashLable3;
    private javax.swing.JButton submit;
    private javax.swing.JComboBox year;
    private javax.swing.JLabel yearLable;
    // End of variables declaration//GEN-END:variables
    
    @Override
    public void keyTyped(KeyEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void keyPressed(KeyEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void keyReleased(KeyEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if(e.getSource()== PaymentCardNumTF){
            if(PaymentCardNumTF.getText().length() >= 4){
                PaymentCardNumTF.setText(PaymentCardNumTF.getText().substring(0, 4));
                PaymentCardNumTF2.requestFocusInWindow();
            }
        }

        else if(e.getSource() == PaymentCardNumTF2)
        {
            if(PaymentCardNumTF2.getText().length()>= 4 ){
                PaymentCardNumTF2.setText(PaymentCardNumTF2.getText().substring(0, 4));
                PaymentCardNumTF3.requestFocusInWindow();
            }
        }

        else if(e.getSource() == PaymentCardNumTF3)
        {
            if(PaymentCardNumTF3.getText().length()>= 4){
                PaymentCardNumTF3.setText(PaymentCardNumTF3.getText().substring(0, 4));
                PaymentCardNumTF4.requestFocusInWindow();
            }
        }

        else if(e.getSource() == PaymentCardNumTF4)
        {
            if(PaymentCardNumTF4.getText().length()>= 4){
                PaymentCardNumTF4.setText(PaymentCardNumTF4.getText().substring(0, 4));
                paymentPanel.requestFocusInWindow();
            }
        }

        else if(e.getSource() == SecurityNumTF)
        {
            if(SecurityNumTF.getText().length()>= 3){
                SecurityNumTF.setText(SecurityNumTF.getText().substring(0, 3));
                paymentPanel.requestFocusInWindow();
            }
        }
    }

}
